package org.example.user.manage.dto;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.converters.string.StringStringConverter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.commons.entity.SysUser;
import org.example.commons.enums.HealthStatusEnum;
import org.example.commons.utils.EnumUtil;
import org.example.user.manage.converter.GetUserNameConverter;

import java.util.Date;

import static org.example.commons.constant.Constants.SIMPLE_DATE_FORMAT;

/**
 * 健康状态 传输展示对象
 *
 * @author bothin
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ColumnWidth(20)
public class SysHealthStatusDTO {
    @ExcelProperty("创建时间")
    private Long statusId;
    /**
     * 用户id
     */
    @ExcelIgnore
    private Long userId;

    /**
     * 住户
     */
    @ExcelProperty(value = "住户", converter = GetUserNameConverter.class)
    private SysUser sysUser;

    /**
     * 状态（0健康，1异常，2确诊）
     */
    @ExcelProperty("状态（0健康，1异常，2确诊）")
    private Integer healthStatus;
    /**
     * 体温
     */
    @ExcelProperty("体温")
    private Float temperature;
    /**
     * 出入次数
     */
    @ExcelProperty("出入次数")
    private Integer accessTimes;
    /**
     * 备注
     */
    @ExcelProperty("备注")
    private String remarks;
    /**
     * 创建时间
     */
    @ExcelProperty(value = "创建时间",converter = StringStringConverter.class)
    private Date createTime;
    /**
     * 修改时间
     */
    @ExcelProperty(value = "修改时间",converter = StringStringConverter.class)
    private Date updateTime;

    public String getHealthStatusMeaning(){
        HealthStatusEnum e = EnumUtil.getByCode(healthStatus, HealthStatusEnum.class);
        return e==null?"":e.getMeaning();
    }

    public String getCreateTime() {
        if (createTime!=null)
            return SIMPLE_DATE_FORMAT.format(createTime);
        else
            return "";
    }

    public String getUpdateTime() {
        if (updateTime!=null)
            return SIMPLE_DATE_FORMAT.format(updateTime);
        else
            return "";
    }
}
